package com.youzu.chuang.screen;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.plaf.basic.BasicArrowButton;
import com.youzu.chuang.utils.FrameRun;

public class MainScreen extends JFrame {

	private static final long serialVersionUID = 1L;
	
	private JButton clientButton = new JButton("Client"); 
	private JButton	serverButton = new JButton("Server");
	
	private BasicArrowButton selectFileButton = new BasicArrowButton(BasicArrowButton.SOUTH);
	private JTextField fileNameTextField = new JTextField();
	
	public MainScreen() {
//		setLayout(new FlowLayout());
		JPanel buttonJPanel = new JPanel();
//		buttonJPanel.add(clientButton, BorderLayout.WEST);
//		buttonJPanel.add(serverButton, BorderLayout.WEST);
		buttonJPanel.add(clientButton);
		buttonJPanel.add(serverButton);
		add(buttonJPanel, BorderLayout.WEST);
		
		JPanel fileJPanel = new JPanel();
		fileNameTextField.setEditable(false);
		fileNameTextField.setText("You pressed cancel");
		fileJPanel.add(fileNameTextField);
		fileJPanel.add(selectFileButton);
		fileJPanel.setLayout(new GridLayout(1,2));
		
		selectFileButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				JFileChooser chooser = new JFileChooser();
				int rVal = chooser.showOpenDialog(MainScreen.this);
				if (rVal == JFileChooser.APPROVE_OPTION) {
					
					fileNameTextField.setText(chooser.getSelectedFile().getName() +"." + chooser.getCurrentDirectory().toString());
//					dir.setText(chooser.getCurrentDirectory().toString());
				}
				if (rVal == JFileChooser.CANCEL_OPTION) {
					fileNameTextField.setText("");
				}
			}
		
		});
		add(fileJPanel, BorderLayout.EAST);
	}
	
	public void registerEvent() {
		
	}

	public static void main(String[] args) {
		MainScreen mainScreen = new MainScreen();
		mainScreen.registerEvent();
		FrameRun.run(mainScreen, 1000, 600);
	}

}
